<?php

class RegionAction extends CommonAction {	
	public function index(){
		$db = M('Region');
		//计算总页数
		$count=$db -> count();
		//实例化分页类
		import ( 'ORG.Util.Page' );
		$p=new Page($count,1000);
		$list = $db->where($map)->where('father_id in(4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,31)') -> order('REGION_NAME_EN ASC')->limit($p->firstRow.', 
'.$p->listRows)->select();
        $pages=$p->show();
		$this->assign('list',$list);
		$this->assign('pages',$pages);
		//dump();
		$this->display();
    }
	
	
	//重写显示页面方法，迎合前端实现ajax数据传输
	public function display($temp = ''){
		$map  = "site_id = ".__SITEID__." and groupname = '".strtolower(GROUP_NAME)."' and (modelname = '".strtolower(MODULE_NAME)."' or modelname = '*') and (actionname = '".strtolower(ACTION_NAME)."' or actionname = '*')";
		$Systempages = M('Systempages') -> where($map) -> find();
		if(IS_AJAX){
			
			$html = '';
			if($Systempages){
				$ModulesDB = D('Modules');
				$this->initView();
				$this->getModulesByID($this->view, $ModulesDB);
				//$html .= $this->view -> fetch(TMPL_PATH.'Home/TemplateDefault/Supplier-header.html');
				$html .= $ModulesDB->getListToString($Systempages['page_view_id'],$this->view,false,true);
				//$html .= $this->view -> fetch(TMPL_PATH.'Home/TemplateDefault/Supplier-footer.html');
			}else{
				$html = $this->fetch($temp);
			}
			$list = $_GET['list'];
			$empty = 1;
			$statu=$list?1:0;
			if($this->get('list')){
				$empty = 0;
			}
			$this->initView();
			die(json_encode(array('empty' => $empty,'tbody'=>$html,'dump'=>$_REQUEST,'statu'=>$statu, 'pages' => $this->view->get('pages'))));
		}else{
			if($Systempages){
				$ModulesDB = D('Modules');
			    $this->initView();
				$this->getModulesByID($this->view, $ModulesDB);
			    $html = $this->view -> fetch(TMPL_PATH.'Home/TemplateDefault/Supplier-header.html');
			    $html .= $ModulesDB->getListToString($Systempages['page_view_id'],$this->view,false,true);
			    $html .= $this->view -> fetch(TMPL_PATH.'Home/TemplateDefault/Supplier-footer.html');
				echo $html;
			}else{
				parent::display($temp);
			}
			
			
		} 
	}
	
}